package com.sunlands.zlcx.usercenter.constant;

import com.sunlands.zlcx.usercenter.exception.BusinessException;

/**
 * @author gaoyanfeng
 * @create 2019-03-26 16:37
 **/
public class RedisKeyConst {
    private static final String REDIS_PREFIX = "TZ_USER_CENTER";
    /**
     * redis中间前缀
     */
    public static final String REDIS_SPLIT_PRE = ":";
    /**
     * redis中间后缀
     */
    public static final String REDIS_SPLIT_SUFFIX = "_";

//    private static final String  USER_BY_PHONE= "user_by_phone";
//    private static final String  USER_TIMING_START_BY_ID= "tongzhuo:timingstart:byuserid";
    private static final String  SMS_PHONE_SEND_FREQUENCY= "sms_phone_send_frequency";
    private static final String  SMS_PHONE_VERIFY_FREQUENCY= "sms_phone_verify_frequency";
    private static final String  SMS_MOBILE= "sms_mobile";
    private static final String  T_PAGE_LAST= "t_page_last";
    private static final String  WECHAT_LOGIN= "wechat_login";
    private static final String  GROUP_SEE= "group_see";
    private static final String  USER_LOCK= "user_lock";
    private static final String  PAUSE_LEARN_TIME_BY_USERID = "pause_learn_time_by_userId";
    private static final String  CONTINUE_LEARN_TIME_BY_USERID = "continue_learn_time_by_userId";
    public static final String  USER_SET_LEARN_TIME = "user_set_learn_time";
//    private static final String  TASK_LOCK = "task_lock";


    /**
     * 获取redis的key
     * @param pre
     * @param argArray
     * @return
     */
    private static String getKeyArray(String pre,Object[] argArray){
        if(argArray != null && argArray.length != 0) {
            StringBuffer sb = new StringBuffer();
            sb.append(REDIS_PREFIX).append(REDIS_SPLIT_PRE).append(pre);
            int start = 0;
            for(int i=0;i< argArray.length;i++){
                if(argArray[i]==null){
                    continue;
                }
                if(start==0){
                    sb.append(REDIS_SPLIT_PRE);
                }else {
                    sb.append(REDIS_SPLIT_SUFFIX);
                }
                sb.append(argArray[i]);
                start ++;
            }
            return sb.toString();
        } else {
            throw new BusinessException("key empty or null argument array");
        }
    }

    private static String getKeyArray(String pre) {
        StringBuffer sb = new StringBuffer();
        sb.append(REDIS_PREFIX).append(REDIS_SPLIT_PRE).append(pre);
        return sb.toString();
    }

//    public static String getUsersByPhone(Object... objects) {
//        return getKeyArray(USER_BY_PHONE, objects);
//    }
//
//    public static String getUsersTimingStartTimeById(Object... objects) {
//        return getKeyArray(USER_TIMING_START_BY_ID, objects);
//    }

    public static String getSendPhoneCodeFrequency(Object... objects) {
        return getKeyArray(SMS_PHONE_SEND_FREQUENCY, objects);
    }

    public static String getVerifyPhoneCodeFrequency(Object... objects) {
        return getKeyArray(SMS_PHONE_VERIFY_FREQUENCY, objects);
    }

    public static String getTpageLast(Object... objects) {
        return getKeyArray(T_PAGE_LAST, objects);
    }
    public static String ifWechatLogin(Object... objects) {
        return getKeyArray(WECHAT_LOGIN, objects);
    }
    public static String ifGroupSee(Object... objects) {
        return getKeyArray(GROUP_SEE, objects);
    }

    public static String getPhoneVerifyCode(Object... objects) {
        return getKeyArray(SMS_MOBILE, objects);
    }

    public static String getUserApplyLockKeyPrefix(Object... objects) {
        return getKeyArray(USER_LOCK, objects);
    }

    public static String getPauseLearnTimeByUserid(Object... objects) {
        return getKeyArray(PAUSE_LEARN_TIME_BY_USERID, objects);
    }

    public static String getContinueLearnTimeByUserid(Object... objects) {
        return getKeyArray(CONTINUE_LEARN_TIME_BY_USERID, objects);
    }

    public static String getUserSetLearnTime() {
        return getKeyArray(USER_SET_LEARN_TIME);
    }

    //    public static String getTaskKey() {
//        return getKeyArray(TASK_LOCK);
//    }
    private static final String REQUEST_TIMES="request_times";
    public static String getRequestTimes(Object... objects){
        return getKeyArray(REQUEST_TIMES, objects);
    }
    public static final String STUDY_NAME="study_name";
    public static String getStudyName(Object... objects){
        return getKeyArray(STUDY_NAME, objects);
    }
    public static final String SHARE_INFO="share_info";
    public static String getShareInfo(Object... objects){
        return getKeyArray(SHARE_INFO, objects);
    }
    public static final String SHARE_ZAN="share_zan_list";
    public static String getShareZanList(Object... objects){
        return getKeyArray(SHARE_ZAN, objects);
    }
    public static final String SHARE_CARD="share_card_list";
    public static String getShareCardList(Object... objects){
        return getKeyArray(SHARE_CARD, objects);
    }
}
